#include <iostream>
#include <string>
using namespace std;
class HowMany2
{
    static int objectCount;
    string name;

public:
    HowMany2(const string &id = "") : name(id)
    {
        objectCount++;
        print("HowMany2()");
    };
    HowMany2(const HowMany2 &h) : name(h.name)
    {
        name += "copy";
        objectCount++;
        print("howmanay2(const HowMany2&)");
    }; // 重写的拷贝构造函数   // 默认我们使用位拷贝来创建对象，正常是可行，一些特殊情况不行？
    void print(const string &msg = "") const
    {
        if (msg.size() != 0)
            cout << msg << ":" << endl;
        cout << name << "objectCount =" << objectCount << endl;
    }
    ~HowMany2()
    {
        objectCount--;
        print("~HowMany2()");
    }
};
int HowMany2::objectCount = 0;
HowMany2 f(HowMany2 x)
{
    x.print("x inside f()");
    return x;
}

int main(){
    HowMany2 h("h");
    cout << "Entering f()" <<endl;
    HowMany2 h2 =f(h);
    h2.print("h2 after call to f()");
    cout << "call  f()" <<endl;
    f(h);
    cout << "after call to f()" <<endl;
}